package CtrLayer;

import ModelLayer.*;
import DBLayer.*;

import java.util.ArrayList;

public class EmployeeCtr {

	public EmployeeCtr()
	{
		
	}
	
	public ArrayList<Employee> findAllEmployees()
	{
		IFDBEmployee dbEmp = new DBEmployee();
	    ArrayList<Employee> allEmp = new ArrayList<Employee>();
	    allEmp = dbEmp.getAllEmployees(false);
	    return allEmp;
	}
	
	public Employee findByName(String name)
    {
        IFDBEmployee dbEmp = new DBEmployee();
        return dbEmp.searchEmployeeName(name);
    }
	
	public Employee findByEmpId(int empId)
    {
        IFDBEmployee dbEmp = new DBEmployee();
        return dbEmp.searchEmpId(empId);
    }
	
	public int deleteByEmpId(int empId)
    {
        IFDBEmployee dbEmp = new DBEmployee();
        return dbEmp.deleteEmployee(empId);
    }
	
	public int updateEmp(int empId, String name, String address, String zip, double salary, String login, String password)
    {
        IFDBEmployee dbEmp = new DBEmployee();
        Employee emp = new Employee();
        emp.setEmpId(empId);
        emp.setName(name);
        emp.setAddress(address);
        emp.setZipCode(zip);
        emp.setSalary(salary);
        emp.setLogin(login);
        emp.setPassword(password);
        return  dbEmp.updateEmployee(emp);
    }
	public void insertNewEmployee(String name, String address, String zip, double salary, String login, String password)
    {    
         Employee empObj = new Employee();
         empObj.setName(name);
         empObj.setAddress(address);
         empObj.setZipCode(zip);
         empObj.setSalary(salary);
         empObj.setLogin(login);
         empObj.setPassword(password);
  
         try{
          DbConnection1.startTransaction();
          DBEmployee dbEmp = new DBEmployee();
          dbEmp.insertEmployee(empObj);
          DbConnection1.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection1.rollbackTransaction();
         }
    }
}
